package dao;

import hibernateUtils.HibernateUtil;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import beans.FacturaBean;

public class HibernateFacturaDAO {
	private static HibernateFacturaDAO instancia;
	private static SessionFactory sf;

	private HibernateFacturaDAO() {

	}

	public static HibernateFacturaDAO getInstancia() {
		if (instancia == null) {
			sf = HibernateUtil.getSessionFactory();
			instancia = new HibernateFacturaDAO();
		}
		return instancia;
	}

	public void grabarFactura(FacturaBean fb) {
		Session session = sf.openSession();
		session.beginTransaction();
		session.save(fb);
		session.flush();
		session.getTransaction().commit();
		session.close();
	}

	public FacturaBean buscarFactura(FacturaBean fb) {
		Session session = sf.openSession();
		FacturaBean f = (FacturaBean) session.get(FacturaBean.class,
				fb.getNumero());
		session.close();
		return f;
	}
}
